package org.csu.mypetstore.web.servlets;



import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.service.AccountService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UserNameIsExistServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("username");

        AccountService accountService = new AccountService();

        Account result = accountService.getAccount(userName);
        resp.setContentType("text/plain");

        PrintWriter out = resp.getWriter();
        if (userName!=null && userName.trim()!=""){
            if (result != null){
                out.print("Exist");
            }else {
                out.print("Not Exist");
            }
        }else  out.print("null");

        out.flush();
        out.close();
    }
}
